#########################################################################
##
## This file is part of the SAMRAI distribution.  For full copyright 
## information, see COPYRIGHT and LICENSE. 
##
## Copyright:     (c) 1997-2019 Lawrence Livermore National Security, LLC
## Description:   Test program for performance of load balancers. 
##
#########################################################################

SAMRAI        = @top_srcdir@
SRCDIR        = @srcdir@
SUBDIR        = source/test/rank_group
VPATH         = @srcdir@
OBJECT        = ../../..
REPORT        = $(OBJECT)/report.xml

CPPFLAGS_EXTRA= -DTESTING=1

default: check

include $(OBJECT)/config/Makefile.config

NUM_TESTS = 6

TEST_NPROCS = @TEST_NPROCS@
QUOTE = \"

CXX_OBJS      = main.o

INPUTS2D = rect.2d.treelb.input rod.2d.treelb.input small_cube.2d.treelb.input  small_sphere.2d.treelb.input
INPUTS3D = plank.3d.treelb.input small_cube.3d.treelb.input

main:	$(CXX_OBJS) $(LIBSAMRAI)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(CXX_OBJS) \
	$(LIBSAMRAI) $(LDLIBS) -o $@

check:
	$(MAKE) check2d
	$(MAKE) check3d

check2d:	main
	@for f in $(INPUTS2D); do	\
	  for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	    echo "    <testcase classname=\"rank_group\" name=$(QUOTE)$$f $$p procs$(QUOTE)>" >> $(REPORT); \
	    $(OBJECT)/config/serpa-run $$p ./main "test_inputs/$$f" | $(TEE) foo; \
	    if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	    echo "    </testcase>" >> $(REPORT); \
	  done \
	done; \
	$(RM) foo

check3d:	main
	@for f in $(INPUTS3D); do	\
	  for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	    echo "    <testcase classname=\"rank_group\" name=$(QUOTE)$$f $$p procs$(QUOTE)>" >> $(REPORT); \
	    $(OBJECT)/config/serpa-run $$p ./main "test_inputs/$$f" | $(TEE) foo; \
	    if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	    echo "    </testcase>" >> $(REPORT); \
	  done \
	done; \
	$(RM) foo

checkcompile: main

checktest:
	$(RM) makecheck.logfile
	$(MAKE) check 2>&1 | $(TEE) makecheck.logfile
	$(OBJECT)/source/test/testtools/testcount.sh $(TEST_NPROCS) $(NUM_TESTS) 0 makecheck.logfile
	$(RM) makecheck.logfile

examples:

perf:

everything:
	$(MAKE) checkcompile || exit 1
	$(MAKE) checktest
	$(MAKE) examples
	$(MAKE) perf

checkclean:
	$(CLEAN_COMMON_CHECK_FILES)

clean: checkclean
	$(CLEAN_COMMON_TEST_FILES)
	$(RM) main

include $(SRCDIR)/Makefile.depend
